﻿function setCookie(cname, cvalue, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
    var expires = "expires=" + d.toUTCString();
    document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/";
}
function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1);
        if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
    }
    return "";
}
function switchMenuOptions(isSwitch) {
    if ($("[id=nav][name=AdminMenu]").html().length > 0 && $("[id=nav][name=AdminMenu]").find('a').length == 0)
    {
        var element = document.getElementById("dropdownMenu_ul");
        element.parentNode.removeChild(element);
        setCookie('isAdminDropDown', false, 1);
    }
    var dropdownType = getCookie('isAdminDropDown');
    if (dropdownType == undefined || dropdownType == null || dropdownType.length == 0) {
        dropdownType == "false"
    }
    var isAdmin = dropdownType == "true";
    if (isSwitch) {
        isAdmin = !isAdmin;
        setCookie('isAdminDropDown', isAdmin, 1);
    }
    if (isAdmin)
    {
        $("[id=nav][name=AdminMenu]").css("height", "auto");
        $("[id=nav][name=AdminMenu]").css("display", "block");
        $("[id=nav][name=AdminMenu]").css("visibility", "visible");
        $("[id=nav][name=EmployeeMenu]").css("height", "0px");
        $("[id=nav][name=EmployeeMenu]").css("display", "none");
        $("[id=nav][name=EmployeeMenu]").css("visibility", "hidden");
    }
    else
    {
        $("[id=nav][name=EmployeeMenu]").css("height", "auto");
        $("[id=nav][name=EmployeeMenu]").css("display", "block");
        $("[id=nav][name=EmployeeMenu]").css("visibility", "visible");
        $("[id=nav][name=AdminMenu]").css("height", "0px");
        $("[id=nav][name=AdminMenu]").css("display", "none");
        $("[id=nav][name=AdminMenu]").css("visibility", "hidden");
    }
    if (isAdmin)
        dropdownType = 'Employee';
    else
        dropdownType = 'Admin';
    $('#dropdownMenu').html(dropdownType);
}

function toggleMenu(menuName) {
    if ($("#" + menuName + " i").hasClass("fa-angle-down")) {
        $('li[prefix="' + menuName + '"]').each(function () {
            $(this).slideUp(600);
        });
        $('#' + menuName + ' i').removeClass('fa-angle-down').addClass('fa-angle-left');
    }
    else {
        $('li[prefix="' + menuName + '"]').each(function () {
            $(this).slideDown(600);
        });
        $('#' + menuName + ' i').removeClass('fa-angle-left').addClass('fa-angle-down');
    }
}
function hideEmptyCols(table) {
    //count # of columns
    var numCols = $("th", table).length;
    for (var i = 1; i <= numCols; i++) {
        var empty = true;
        //grab all the <td>'s of the column at i
        $("td:nth-child(" + i + ")", table).each(function (index, el) {
            //check if the <span> of this <td> is empty
            if (el.innerHTML.trim().length > 0) {
                empty = false;
                return false; //break out of each() early
            }
        });
        if (empty) {
            $("td:nth-child(" + i + ")", table).hide(); //hide <td>'s
            $("th:nth-child(" + i + ")", table).hide(); //hide header <th>
        }
    }
}
function MoveItemsToHeader() {
    try {
        if ($('#_SaveSource').length > 0) {
            $('#_SaveDestination a').attr('id', $('#_SaveSource a').attr('id'));
            $('#_SaveDestination a').attr('onclick', $('#_SaveSource a').attr('onclick'));
            $('#_SaveSource').html('');
        }
        else
            $('#_SaveDestination').html('');
    }
    catch (ex)
    { }
    try {
        if ($('#_PrintSource').length > 0) {
            $('#_PrintDestination a').attr('id', $('#_PrintSource a').attr('id'));
            $('#_PrintDestination a').attr('onclick', $('#_PrintSource a').attr('onclick'));
            $('#_PrintSource').html('');
        }
        else
            $('#_PrintDestination').html('');
    }
    catch (ex)
    { }
    try {
        if ($('#_HelpSource').length > 0) {
            $('#_HelpDestination a').attr('href', $('#_HelpSource a').attr('href'));
            $('#_HelpSource').html('');
        }
        else
            $('#_HelpDestination').html('');
    }
    catch (ex)
    { }
}